<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<%@ include file="/common/plateform/include/common-base.jsp"%>
	<title>系统代码集</title>
	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">
	<!-- top start -->
	<%@include file="/common/plateform/top.jsp" %>
	<!-- top end -->
	<!-- left start -->
	<%@include file="/common/plateform/left.jsp" %>
	<!-- left end-->



	<div class="content-wrapper">

		<c:set var="sysEname" value="${param.sysName}"/>

		<!-- Main start -->
		<section class="content">
			<div class="row">
				<div class="col-xs-12">
					<div class="box box-info">
						<div class="box-header">
							<h3 class="box-title"><i class="fa fa-user"></i> 系统数据字典
								　　　                  <button class="btn btn-success" type="button" onclick="toAdd('parent');">增加</button>
								<button class="btn btn-info" type="button" onclick="del();">删除</button>
								<button class="btn btn-info" type="button" onclick="toEdit();">修改</button>
								<button class="btn btn-warning" type="button" onclick="refresh();">刷新</button>
							</h3>
						</div>
						<!-- /.box-header -->
						<div class="box-body">

							<center>
								<form id="searchFrom" class="form-horizontal">
									<input type="hidden" name="doCode" value="dictCateList"/>
									<c:if test="${empty param.sysEname}">
										<input type="hidden" name="sysEname" value="${sysName}"/>
									</c:if>
									<c:if test="${not empty param.sysEname}">
										<input type="hidden" name="sysEname" value="${param.sysEname}"/>
									</c:if>
									科目名称：<input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="cateCname" id="cateCname" value="" />
									科目标识: <input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="cateEname" id="cateEname" value="" />

									<button type="button" class="btn btn-primary" onclick="getTableData();"><i class="fa fa-search"></i>查询</button>
									<button  type="button" class="btn btn-primary" onclick="cleanData('searchFrom');">重置 </button>
								</form>
							</center>

							<table id="example" class="table table-bordered " >
								<thead>
								<tr>
									<th>科目名称</th>
									<th>科目标识</th>
									<th>状态</th>
									<th>描述</th>
									<th>操作</th>
								</tr>
								</thead>
								<tbody id="myList">
								</tbody>
							</table>
							<center>
								<ul id="pageList"></ul>
							</center>
						</div>
					</div>
				</div>
			</div>
		</section>

		<!-- Main end -->

		<div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">科目信息</font>&nbsp;</h4>
					</div>

					<div class="modal-body">
						<form class="form-horizontal" role="form" id="orgForm" action="javascript:;">
							<input type="hidden" class="clean" name="formToken" id="formToken" value="${formToken}"/>
							<input type="hidden" class="clean"  name="cateId" id="cateId" value="${item.cateId}"/>
							<input type="hidden" class="clean"  name="oldCateEname" id="oldCateEname" value="${item.cateEname}"/>
							<c:if test="${empty param.sysEname}">
								<input type="hidden" name="sysEname" value="${sysName}"/>
							</c:if>
							<c:if test="${not empty param.sysEname}">
								<input type="hidden"   name="sysEname" value="${param.sysEname}"/>
							</c:if>
							<input type="hidden" name="doCode" value="dictCateSave"/>
							<div class="box-body">
								<div class="form-group">
									<label  class="col-sm-4 control-label" >科目中文名称</label>
									<div class="col-sm-6">
										<input type="text" class="form-control clean" id="cateCname"  name="cateCname" required placeholder="必填项">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-4 control-label">科目标识</label>
									<div class="col-sm-6">
										<input type="text" class="form-control clean" id="cateEname" name="cateEname" required placeholder="必填项">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-4 control-label">描述</label>
									<div class="col-sm-6">
										<input type="text" class="form-control clean" id="cateRemark" name="cateRemark" placeholder="">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-4 control-label">状态</label>
									<div class="col-sm-6">
										<input type="radio" checked="checked" value="1" name="cateStatus"> <i></i> 启用
										<input type="radio" value="0" name="cateStatus"> <i></i> 停用
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-4 control-label">显示类型</label>
									<div class="col-sm-6">
										<select name="viewType" class="form-control clean" style="width:100px;">
											<option value="">--默认--</option>
											<option value="1">三级联动</option>
											<option value="2">树形结构</option>
										</select>
										<div class="f12">注：目前只支持级联才选，其他默认</div>
									</div>
								</div>
							</div>
							<div class="box-footer">
								<button type="button" class="btn btn-primary pull-left" onclick="cannel();">取消</button>
								<button type="button" class="btn btn-primary pull-right" onclick="save('orgForm');">提 交</button>
							</div>
						</form>
					</div>



				</div>
				<!-- /.modal-content -->
			</div>
		</div>
		<div class="modal fade" id="my_modal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog" style="width:1020px;">
				<div class="modal-content" id="dataItemManager"></div>
			</div>
		</div>

		<script type="text/template" id="dataList">
			<? for ( var i = 0; i < rows.length; i++) {?>
			<tr id=<?=rows[i].cateId?> >
				<th style="display:none;"><?=rows[i].cateId?></th>
				<td><?=rows[i].cateCname?></td>
				<td><?=rows[i].cateEname?></td>
				<td><?if("1"==rows[i].cateStatus){?><font color=blue>启用</font>
					<?}else{?><font color=red>停用</font><?}?>
				</td>
				<td><?=rows[i].cateRemark?></td>
				<td><a href="javascript:void('0');" onclick="itemTrees('<?=rows[i].cateEname?>','<?=rows[i].cateCname?>','<?=rows[i].viewType?>')">条目管理</a></td>
			</tr>
			<?}?>
		</script>


		<script>
            var clickMenu= 'dict-list';
            var id;
            var cateEname;
            $(function () {
                getTableData();
                $('#example tbody').on('click','tr', function (e) {
                    if ( $(this).hasClass('selected') ) {
                        //$(this).removeClass('selected');
                    }  else {
                        $('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                    }
                    id = $('tr.selected th').eq(0).html();
                    cateEname = $('tr.selected td').eq(1).html();
                    //  console.log($('tr.selected td').eq(1).html())
                } );
            });

            //设置模态框隐藏事件钩子
            $( '#my_modal' ).on( 'hide.bs.modal' ,function(e){
                mytools.cleanData("#orgForm");
            });

            //设置模态框隐藏事件钩子
            $( '#my_modal' ).on( 'show.bs.modal' ,function(e){
                $.ajax({ type:'post',url:'${ctx}/sendPage/token?token=true', dataType:'json',
                    success: function(myData){
                        //console.log(myData);
                        $('#formToken').val(myData);
                    }
                });
            });

            function cleanData(id){
                $(':input','#'+id)
                    .not(':button, :submit, :reset, :hidden,:radio')
                    .val('')
                    //.removeAttr('checked')
                    .removeAttr('selected');
            }


            function getTableData(){
                $.ajax({url:common_list_url,
                    type: "get",dataType: "json",
                    data:$('#searchFrom').serialize()+getCurrentPage(dictUrl+"?"+$('#searchFrom').serialize(),8),
                    error: function(){   alert('异常错误'); },
                    success: function(myData){
                        var data = baidu.template('dataList',myData);
                        $("#myList").html(data);
                        var option= {ele:$("#pageList")[0],total:myData.total,fn:getTableData,
                            url:dictUrl+"?"+$('#searchFrom').serialize()}
                        generatePages(option);
                    }
                });
            }


            function toAdd(){
                $('#my_modal').modal('show');
                setToken();
            }

            function itemTrees(code,cname,viewType){
                $("#dataItemManager").load("${ctx}/template/uct/dict-detail.html",function(){loadItems(code,cname,viewType);});
                $('#my_modal2').modal('show');
            }

            function toEdit(){
                if(id=="undefined" || id =="" || id == null){
                    layer.alert('请先选中一条数据！', {
                        skin: 'layui-layer-molv'
                        ,closeBtn: 0
                    });
                    return;
                }else{
                    $.ajax({type:'get', url:common_info_url, dataType:'json',
                        data:{'cateId':id,'doCode':'dictCateInfo'},
                        success: function(myData){
                            //console.log(myData);
                            FormUtil.fillData("#orgForm", myData,"id");
                            DictUtil.checkRadioDict("cateStatus", myData.cateStatus);
                            $('#my_modal').modal('show');
                            setToken();
                        }
                    });
                }
                //$('#my_modal').modal('show');
            }

            function del(){
                if(id=="undefined" || id =="" || id == null){
                    layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv' ,closeBtn: 0 });
                    return;
                }else{
                    layer.confirm('您确认要进行删除操作？', { btn: ['确认','取消'] },
                        function(){
                            $.ajax({type:'post', url:common_submit_url, dataType:'json',
                                data:{'cateId':id,'doCode':'dictCateDel'},
                                success: function(myData){
                                    if(myData.flag=='T'){
                                        layer.alert('操作成功！', {skin: 'layui-layer-molv',closeBtn: 0 });
                                        id = "";
                                        refresh();
                                    }else{
                                        layer.alert('操作失败！'+myData.msg);
                                    }
                                }
                            });
                        },
                        function(){}
                    );
                }
            }
            function save(formId){
                if(!$("#" + formId)[0].checkValidity()){
                    layer.alert("请先完善必填项！");
                    return ;
                }
                $.ajax({ type:'post',url:common_submit_url,dataType:'json',
                    data:$("#"+formId).serialize(),
                    success: function(myData){
                        //console.log(myData);
                        if(myData.flag=='T'){
                            layer.alert('操作成功！', {skin:'layui-layer-molv',closeBtn:0});
                            $('#my_modal').modal('hide');
                            refresh();
                        }else{
                            layer.alert(myData.msg);
                        }
                    }
                });
            }

            function cannel(){
                $('#my_modal').modal('hide');

            }
            function deleteAllRow(){
                var tb = document.getElementById('example');
                if(tb){
                    var rowNum=tb.rows.length;
                    for (i=1;i<rowNum;i++){
                        tb.deleteRow(i);
                        rowNum=rowNum-1;
                        i=i-1;
                    }
                }
            }

            function refresh(){
                //window.location.reload();
                getTableData();
            }
            function setToken(){
                $.ajax({ type:'get',url:'${ctx}/sendPage/token?token=true',dataType:'text',
                    success: function(myData){
                        $('#formToken').val(myData);
                    }
                });
            }
		</script>



	</div>

</div>
</body>








<!-- foot start -->

<%@include file="/common/plateform/foot.jsp" %>
<!-- foot start -->

</html>
